package ro.myApp.esb.service;

import java.io.File;
import java.io.FileFilter;
import java.util.LinkedList;
import java.util.List;

import org.jboss.seam.annotations.Logger;
import org.jboss.seam.log.Log;

public class EsbConfigBuilder {
	
	private final static String configFilePattern = "mule-config(.)*.xml";
	
	@Logger
	private static Log log;
	
	public static String[] getConfigFiles() {
		String searchPath = System.getProperty("jboss.server.config.url")
				.concat("mule/").substring(6);
		List<String> filesFound = new LinkedList<String>();
		try {
			final FileFilter filter = new FileFilter() {
				public boolean accept(File file) {
					return file.getName().matches(configFilePattern)
							&& file.isFile();
				}
			};

			File folderDeploy = new File(searchPath);
			for (File f : folderDeploy.listFiles(filter)) {
				filesFound.add(f.getAbsolutePath());
			}
		} catch (Exception e) {
			log.error("Error at: " + searchPath);
			e.printStackTrace();
		}
		return filesFound.toArray(new String[0]);
	}
}
